class Merchant {
  final String? id;
  final String name;
  final String? merchantName;
  final String miniProgramName;
  final String legalPersonName;
  final String legalPersonPhone;
  final String? address;
  final String? status;
  final String? owner;
  final String? mchid;
  final String? appid;
  final String? cloudFunctionUrl;
  final int? createdAt;
  final int? updatedAt;

  Merchant({
    this.id,
    required this.name,
    this.merchantName,
    required this.miniProgramName,
    required this.legalPersonName,
    required this.legalPersonPhone,
    this.address,
    this.status,
    this.owner,
    this.mchid,
    this.appid,
    this.cloudFunctionUrl,
    this.createdAt,
    this.updatedAt,
  });

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'merchant_name': merchantName,
      'miniapp_name': miniProgramName,
      'legal_person': legalPersonName,
      'legal_person_phone': legalPersonPhone,
      'address': address,
      'status': status,
      'owner': owner,
      'mchid': mchid,
      'appid': appid,
      'cloud_function_url':cloudFunctionUrl,
      'createdAt': createdAt,
      'updatedAt': updatedAt,
    };
  }

  factory Merchant.fromJson(Map<String, dynamic> json) {
    return Merchant(
      id: json['id']?.toString(),
      name: json['name'] as String? ?? '未知商户',
      merchantName: json['merchant_name'] as String?,
      miniProgramName: json['miniapp_name'] as String? ?? '未知小程序',
      legalPersonName: json['legal_person'] as String? ?? '未知法人',
      legalPersonPhone: json['legal_person_phone'] as String? ?? '未知电话',
      address: json['address'],
      status: json['status']?.toString(),
      owner: json['owner']?.toString(),
      mchid: json['mchid']?.toString(),
      appid: json['appid']?.toString(),
      cloudFunctionUrl: json['cloud_function_url'] as String?,
      createdAt: json['createdAt'] as int?,
      updatedAt: json['updatedAt'] as int?,
    );
  }
}
